<?php
/**
 * Geneone: Content Management Framework
 * Blog Entry Object View
 *
 * http://geneone.neondragon.net/
 *
 * @package Geneone
 * @author Khlo
 * @version 1.0
 * @copyright 2004-2006 Geneone Development Team
 */
 
require_once ("Gene/Object/View.php");

class Gene_Object_View_Blogentry extends Gene_Object_View {
	/**
	 * Class Constructor
	 *
	 * @var object $model Gene_Object_Model object
	 */
	function Gene_Object_View_Blogentry(&$model) {
		$this->model =& $model;
	}
	
	/**
	 * Show this object. Returns HTML output code for object.
	 *
	 * @var array $actions Additional Arguments
	 *
	 * @return string HTML output for object.
	 */
	function view($actions=array()) {
		$tpl =& Gene::getTemplate();
		
		/* General Object Information */
		$info = $this->model->get();
		
		$tpl->assign ("pagetitle", $info['title']);
		$tpl->assign ("object", $info);
		
		/* Parts */
		if (strpos($info['content'], '<!--newpage-->')) {
			$tpl->assign ("multipart", true);
			
			$sections = explode('<!--newpage-->', $info['content']);
			$tpl->assign ("blurb", $sections[0]);
			unset($sections[0]);
			$tpl->assign ("sections", $sections);
			
			$showSection = Gene_Request::getInteger("section", GENE_REQUEST_GET);
			if ($showSection && isset($sections[$showSection])) {
				$tpl->assign ("showsection", $showSection);
			} else {
				$tpl->assign ("showsection", 1);
			}
		}
		
		/* Taxonomy */
		$taxonomy =& $this->model->getTaxonomyEntry($info['parent']);
		$set =& $taxonomy->getSet();
		$tpl->assign ("categories", $set->getLabels());
		$tpl->assign ("entrycategories", $taxonomy->getAll());
		
		/* Parents */
		$parents = $this->model->getParents();
		$tpl->assign ("parents", $parents);

		$p = count($parents)-1;
		$parent = $parents[$p];
		$tpl->assign ("parent", $parent);
		
		/* Childs */
		$childs = $this->model->getChilds(array("tables" => Gene::tableName("object_guests")));
		$tpl->assign ("childs", $childs);
		
		// Taxonomy & Similar Entries
		$tpl->assign ("labels", $taxonomy->getAll());
		$tpl->assign ("similar", $taxonomy->findSimilar());
		
		/* Overwrite alternate URLs to add Atom Feed */
		$tpl->assign("alternate", array());
		$tpl->append("alternate", array(
			"type" => "application/atom+xml",
			"title" => $parent['title'],
			"url" => Gene::xmlLink($parent)
		));
		$tpl->append("alternate", array(
			"type" => "application/atom+xml",
			"title" => 'Comments: '.$info['title'],
			"url" => Gene::xmlLink($info)
		));
		
		$tpl->append ("portlets", "blogentry");
		
		return $tpl->fetch("objects/blogentry/view");
	}
	
	
	/**
	 * Callback function to specify object specific edit actions.
	 */
	function getCustomEditActions() {
		$tpl =& Gene::getTemplate();
		$info = $this->model->get();
		
		/* Taxonomy */
		$categories = $this->model->getTaxonomyEntry($info['parent']);
		$tpl->assign ("entrycategories", $categories->getAll());
		
		$set =& $categories->getSet();
		$tpl->assign ("categories", $set->getLabels());
	}
	
	/**
	 * Displays the object creation form for this type of object.
	 *
	 * @static
	 *
	 * @var object $parent Parent Object
	 *
	 * @return string HTML output for object creation.
	 */
	function create(&$parent) {
		$tpl =& Gene::getTemplate();
		
		/* Taxonomy */
		$set =& $parent->getTaxonomySet();
		$tpl->assign ("categories", $set->getLabels());
		
		return $tpl->fetch("objects/blogentry/create");
	}
	
	/**
	 * Creates the new object.
	 * 
	 * Objects can implement their own creation routines here to fiddle
	 * the user input before sending to Gene_Object::create() or return a
	 * PEAR::raiseError if input is invalid
	 */
	function doCreate($type, $title='', $desc='', $content='', &$parentobj, $options=array(), $draft=false) {
		$categories = Gene_Request::getArray("categories", GENE_REQUEST_POST);

		return parent::doCreate($type, $title, $desc, $content, $parentobj, array("categories" => $categories), $draft);
	}
	
	/**
	 * Edits the current object.
	 *
	 * Objects can implement callback routines here.
	 */
	function doEdit($options=array()) {
		$options['options']['categories'] = Gene_Request::getArray("categories", GENE_REQUEST_POST);
		
		return $this->model->setContent($options);
	}
}
 
?>